<?php
namespace Account;

/**
 * Description of DashboardController
 *
 * @author dung
 */
use AuthorizedController,
    Config,
    Input,
    Jinput,
    HDServices,
    View,
    Redirect,
    Response,
    Sentry,
    Lang;

class DashboardController extends AuthorizedController
{
    //put your code here
    public function __construct()
    {
        return $this->beforeFilter('auth');
    }

    public function getIndex()
    {
        $data = array();
        $data['action'] = Input::get('act', '');
        $user = Sentry::getUser();

        // get statistic of user
        $data['statistic'] = HDServices::accountServices()->statisticUser($user->id);
        if ($data['action'] == 'lesson')
            $data['lessons'] = $user->lessons()->paginate();
        else if ($data['action'] == 'video')
            $data['videos'] = $user->videos()->paginate();
        else if ($data['action'] == 'lyric')
            $data['lyrics'] = $user->lyrics()->paginate();
        else if ($data['action'] == 'followers')
            $data['followers'] = $user->followers()->paginate();
        else {
            $data['lessons'] = $user->lessons()->take(6)->orderBy('lessons.id', 'DESC')->get();
            $data['videos'] = $user->videos()->take(6)->orderBy('videos.id', 'DESC')->get();
            $data['follows'] = $user->follows()->paginate();
        }

        return View::make('frontend/account/dashboard/dashboard', compact('data'));
    }
}
